import java.lang.*;
import java.lang.Exception;

class SendEvent extends CommEvent {	
	public SendEvent(Channel c, Object o) {
		channel = c;
		obj = o;
	}
	
	public void Sync() throws InterruptedException{
		synchronized (Lock.lock) {
			Enqueue();
			if (!Poll()) {
				while (channel.sendQueue.contains(this)) {
					Lock.lock.wait();
				}
				Lock.lock.notifyAll();
			}
		}
	}
	
	public boolean Poll() {
		synchronized (Lock.lock) {
			if (channel.sendQueue.contains(this)) {
				return false;
			}
			Lock.lock.notifyAll();
			return true;
		}
	}
	
	public void Enqueue() {
		synchronized (Lock.lock) {
			channel.sendQueue.add(this);
			Lock.lock.notifyAll();
		}
	}
	
	public void Dequeue() {
		synchronized (Lock.lock) {
			channel.sendQueue.remove(this);
			Lock.lock.notifyAll();
		}
	}
		
	public boolean CommOccurred() {
		synchronized (Lock.lock) {
			if (channel.sendQueue.contains(this)) {
				return false;
			}
			return true;
		}
	}
}
